package com.huali.principle.composite;

// 数据库连接类
class DBConnection {
    public String getConnection() {
        return "MySQL 数据库连接";
    }
}

// 产品 DAO 类，使用合成复用
class ProductDao {
    private DBConnection dbConnection;

    public ProductDao(DBConnection dbConnection) {
        this.dbConnection = dbConnection;
    }

    public void addProduct() {
        String conn = dbConnection.getConnection();
        System.out.println("使用 " + conn + " 增加产品");
    }
}

public class CompositeReusePrinciple {
    public static void main(String[] args) {
        DBConnection dbConnection = new DBConnection();
        ProductDao productDao = new ProductDao(dbConnection);
        productDao.addProduct();
    }
}